package com.lunchspothack;



import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ViewCheckinsActivity extends Activity {
	private static final String TAG = ViewCheckinsActivity.class.getSimpleName();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.checkins_view);

	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		
		
		updateCheckinsList();
		
	}
	
	public void updateCheckinsList() {
		
		List<Lunchspot> checkinPlaces = FacebookUtil.getCheckins(getBaseContext());
		
		ListView lv = (ListView) findViewById(R.id.listCheckins); 
        lv.setAdapter(new ArrayAdapter<Lunchspot>(this, R.layout.checkins_view_list_item, checkinPlaces) {

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				Lunchspot spot = getItem(position);
				if (convertView == null) {
					LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
					convertView = vi.inflate(R.layout.checkins_view_list_item, null);
				}
				
				TextView tv = (TextView) convertView.findViewById(R.id.textCheckinName);
				tv.setText(spot.getName());
		 
				tv = (TextView) convertView.findViewById(R.id.textCheckinLatitude);
				tv.setText(spot.getLatitude());

				tv = (TextView) convertView.findViewById(R.id.textCheckinLongitude);
				tv.setText(spot.getLongitude());
				
				return convertView;
			}
        	
        }); 
		
		
	}
	

	

	
 
}
